﻿using System;
using Microsoft.VisualStudio.SharePoint;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;

namespace CodeCounsel.SharePoint.DevTools
{
    class SharePointServices
    {
        public ISharePointProject Project { get; set; }
        public ISharePointProjectService ProjectService { get; set; }

        public SharePointServices(Project project)
        {
            ProjectService = GetProjectService(project.DTE);
            Project = ProjectService.Convert<Project, ISharePointProject>(project);
        }

        internal static ISharePointProjectService GetProjectService(DTE designTimeEnvironment)
        {
            IOleServiceProvider sp = designTimeEnvironment as IOleServiceProvider;
            return (new ServiceProvider(sp).GetService(typeof(ISharePointProjectService)) as ISharePointProjectService);
        }
    }
}
